package com.lycafly;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Fullscreen;
import org.androidannotations.annotations.NoTitle;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.AnimationRes;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

@NoTitle
@Fullscreen
@EActivity(R.layout.activity_splash)
public class SplashActivity extends Activity {

	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		Window window = getWindow();
		window.setFormat(PixelFormat.RGBA_8888);
	}

	@AnimationRes(R.anim.alpha)
	Animation animAlpha;

	@AnimationRes(R.anim.translate)
	Animation animTranslate;

	@ViewById(R.id.lin_lay)
	LinearLayout l;

	@ViewById(R.id.logo)
	ImageView iv;

	@AfterViews
	void doUi() {
		animAlpha.reset();
		l.clearAnimation();
		l.startAnimation(animAlpha);
		animTranslate.reset();
		iv.clearAnimation();
		iv.startAnimation(animTranslate);
		animTranslate.setAnimationListener(new AnimationListener() {

			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub

			}

			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub

			}

			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				startMainActivity();
			}
		});
	}

	@UiThread(delay = 10)
	void startMainActivity() {
		Intent intent = new Intent(SplashActivity.this,
				MainActivity_.class);
		startActivity(intent);
		overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
		finish();
	}

}
